/**
 * yyyy-MM-dd hh:mm:ss
 * yyyy-MM-dd
 * yyyy/MM/dd
 * MM/dd/yyyy
 */
Date.prototype.format = function(format)   
{   
   var o = {   
     "M+" : this.getMonth()+1, //month   
     "d+" : this.getDate(),    //day   
     "h+" : this.getHours(),   //hour   
     "m+" : this.getMinutes(), //minute   
     "s+" : this.getSeconds(), //second   
     "q+" : Math.floor((this.getMonth()+3)/3), //quarter   
     "S" : this.getMilliseconds() //millisecond   
   };
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,   
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   for(var k in o)if(new RegExp("("+ k +")").test(format))   
     format = format.replace(RegExp.$1,   
       RegExp.$1.length==1 ? o[k] :    
         ("00"+ o[k]).substr((""+ o[k]).length));   
   return format;   
};

/**
 * 将字符串转换为Date
 * @param str yyyyMMdd格式的字符串
 * @returns {Date}
 */
function string8ToDate(str) {
	if (str && str.length == 8) {
		var year = str.substring(0, 4);
		var month = str.substring(4, 6);
		var day = str.substring(6, 8);
		return new Date(year, month - 1, day);
	}
	return new Date();
}

/**
 * 将字符串转换为Date
 * @param str yyyyMMddHHmmss格式的字符串
 * @returns {Date}
 */
function string14ToDate(str) {
	if (str && str.length == 8) {
		var year = str.substring(0, 4);
		var month = str.substring(4, 6);
		var day = str.substring(6, 8);
		var hour = str.substring(8, 10);
		var min = str.substr(10, 12);
		var sec = str.substr(12, 14);
		return new Date(year, month - 1, day, hour, min, sec);
	}
	return new Date();
}

/**
 * 将Date转换为字符串
 * @param date
 * @returns {String}
 */
function dateToString8(date) {
	return date.getFullYear() + "" + (date.getMonth() + 1) + "" + date.getDate();
}

/**
 * 将Date转换为字符串
 * @param date
 * @returns {String}
 */
function dateToString14(date) {
	return date.getFullYear() + "" + (date.getMonth() + 1) + "" + date.getDate() + "" + date.getHours() + "" +date.getMinutes() + "" + date.getSeconds();
}